home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Applications / PICSee Dust 1.01 / Quaternary Source / ReadPicture.c < prev    next >
C/C++ Source or Header  |  1995-11-01  |  905b  |  48 lines

  1. #include "ReadPicture.h"
  2.  
  3. PicHandle ReadPicture(FSSpec *pictFile) {
  4.     PicHandle thePic;
  5.     short fileRefNum;
  6.     OSErr myErr;
  7.     long picSize;
  8.  
  9.     myErr = FSpOpenDF(pictFile, fsCurPerm, &fileRefNum);
  10.     if (myErr != noErr)  {
  11.         SysBeep(10);
  12.         return(NULL);
  13.     }
  14.  
  15.     myErr = GetEOF(fileRefNum, &picSize);
  16.     if (myErr != noErr)  {
  17.         SysBeep(10);
  18.         return(NULL);
  19.     }
  20.  
  21.     picSize -= 512;    // Don't include pict file header data
  22.     thePic = (PicHandle)NewHandle(picSize);
  23.     if (thePic == NULL)
  24.         return(NULL);
  25.     HNoPurge((Handle)thePic);
  26.  
  27.     myErr = SetFPos(fileRefNum, fsFromStart, 512);
  28.     if (myErr != noErr)  {
  29.         SysBeep(10);
  30.         return(NULL);
  31.     }
  32.  
  33.     HLock((Handle)thePic);
  34.     myErr = FSRead(fileRefNum, &picSize, (Ptr)*thePic);
  35.     if (myErr != noErr)  {
  36.         SysBeep(10);
  37.         return(NULL);
  38.     }
  39.     HUnlock((Handle)thePic);
  40.  
  41.     myErr = FSClose(fileRefNum);
  42.     if (myErr != noErr)  {
  43.         SysBeep(10);
  44.         return(NULL);
  45.     }
  46.     
  47.     return(thePic);
  48. } // END ReadPicture